package com.heyue.ems.service.impl;

import java.util.List;
import com.heyue.common.core.utils.DateUtils;
import com.heyue.common.core.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.heyue.ems.mapper.EmsOrderMapper;
import com.heyue.ems.domain.EmsOrder;
import com.heyue.ems.service.IEmsOrderService;


/**
 * 同行单（业务）Service业务层处理
 * 
 * @author WChu
 * @date 2021-07-26
 */
@Service
public class EmsOrderServiceImpl implements IEmsOrderService 
{
    @Autowired
    private EmsOrderMapper emsOrderMapper;

//    @Autowired
//    private SysUserServiceImpl sysUserService;

    /**
     * 查询同行单（业务）
     * 
     * @param id 同行单（业务）ID
     * @return 同行单（业务）
     */
    @Override
    public EmsOrder selectEmsOrderById(Long id)
    {
        return emsOrderMapper.selectEmsOrderById(id);
    }

    /**
     * 查询同行单（业务）列表
     * 
     * @param emsOrder 同行单（业务）
     * @return 同行单（业务）
     */
    @Override
    public List<EmsOrder> selectEmsOrderList(EmsOrder emsOrder)
    {
        return emsOrderMapper.selectEmsOrderList(emsOrder);
    }

    /**
     * 新增同行单（业务）
     * 
     * @param emsOrder 同行单（业务）
     * @return 结果
     */
    @Override
    public int insertEmsOrder(EmsOrder emsOrder)
    {
        return emsOrderMapper.insertEmsOrder(emsOrder);
    }

    /**
     * 修改同行单（业务）
     * 
     * @param emsOrder 同行单（业务）
     * @return 结果
     */
    @Override
    public int updateEmsOrder(EmsOrder emsOrder)
    {
//        String userName = SecurityUtils.getUsername();
//        long userId = SecurityUtils.getUserId();
//        Boolean flag = SecurityUtils.isAdmin(userId);
//        System.out.println(userName);
//        System.out.println(userId);
//        System.out.println(flag);

//        String roleName = sysUserService.selectUserRoleGroup(name);
//        System.out.println(roleName);
//        String roleName = selectUserRoleGroup(name);
//        System.out.println(roleName);


        emsOrder.setUpdateTime(DateUtils.getNowDate());
        return emsOrderMapper.updateEmsOrder(emsOrder);
    }

    //判断是否是管理员
    @Override
    public Boolean isAdmin(){
        String userName = SecurityUtils.getUsername();
        long userId = SecurityUtils.getUserId();
        Boolean flag = SecurityUtils.isAdmin(userId);
        return flag;
    }

    /**
     * 批量删除同行单（业务）
     * 
     * @param ids 需要删除的同行单（业务）ID
     * @return 结果
     */
    @Override
    public int deleteEmsOrderByIds(Long[] ids)
    {
        return emsOrderMapper.deleteEmsOrderByIds(ids);
    }

    /**
     * 删除同行单（业务）信息
     * 
     * @param id 同行单（业务）ID
     * @return 结果
     */
    @Override
    public int deleteEmsOrderById(Long id)
    {
        return emsOrderMapper.deleteEmsOrderById(id);
    }
}
